package com.cryptoneedle.garden.service.dolphin;

import com.cryptoneedle.garden.entity.source.metadata.SourceCatalog;
import com.cryptoneedle.garden.entity.source.metadata.SourceDatabase;
import com.cryptoneedle.garden.entity.source.metadata.SourceTable;
import com.cryptoneedle.garden.service.crud.garden.source.*;
import com.cryptoneedle.garden.service.seatunnel.SeatunnelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>description:  </p>
 *
 * @author CryptoNeedle
 * @date 2025-11-05
 */
@Service
public class DolphinSourceService {

    @Autowired
    private DolphinSourceService dolphinSourceService;

    @Autowired
    private SeatunnelService seatunnelService;

    @Autowired
    private FoundSourceService select;
    @Autowired
    private AddSourceService add;
    @Autowired
    private PatchSourceService patch;
    @Autowired
    private SaveSourceService save;
    @Autowired
    private DeleteSourceService delete;

    public void generateSeatunnelWorkflow(String catalogName, String databaseName) {
        SourceCatalog catalog = select.catalog(catalogName);
        SourceDatabase database = select.database(catalogName, databaseName);
        List<SourceTable> tables = select.tables(catalogName, databaseName);

        // 查询数据库所有工作流

        for (SourceTable table : tables) {
            dolphinSourceService.generateSeatunnelTaskDefinition(catalog, database, table);
        }
    }

    public void generateSeatunnelTaskDefinition(SourceCatalog catalog, SourceDatabase database, SourceTable table) {
        String seatunnel = seatunnelService.seatunnelScript(catalog, database, table);

        // 查询 DolphinTaskDefinition

        // 修改 DolphinTaskDefinition
    }
}